{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# DG求解一维热传导方程"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## DG单元操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "jupyter": {
     "source_hidden": true
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "┌ Info: Recompiling stale cache file /Users/apple/.juliapro/JuliaPro_v1.2.0-2/compiled/v1.2/Plots/ld3vC.ji for Plots [91a5bcdd-55d7-5caf-9e0b-520d859cae80]\n",
      "└ @ Base loading.jl:1240\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "dmatrix (generic function with 1 method)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "using DifferentialEquations, Plots, LinearAlgebra, BenchmarkTools, Sundials\n",
    "\n",
    "function legendregausslobatto(m)\n",
    "    # Compute the m'th order Legendre-Gauss-Lobatto quadrature points, x, and weights, w\n",
    "    x = zeros(m+1); w = zeros(m+1)\n",
    "\n",
    "    if m==1\n",
    "        x[1]=-1.0; x[2]=1.0\n",
    "        w[1]= 1.0; w[2]=1.0\n",
    "        return x\n",
    "    end\n",
    "\n",
    "    if m==2\n",
    "        x[1]=-1.0; x[2]=0.0; x[3]=1.0\n",
    "        w[1]= 1/3; w[2]=4/3; w[3]=1/3\n",
    "        return x\n",
    "    end\n",
    "\n",
    "    J = zeros(m-1, m-1); h1 = 2*(0:m-2).+2\n",
    "    aux = broadcast(sqrt, (1:m-2).*((1:m-2).+ 2).*((1:m-2).+1).*((1:m-2).+1)./(h1[1:m-2].+1)./(h1[1:m-2].+3))\n",
    "    J[1:m-2,2:m-1] = Diagonal(2.0 ./(h1[1:m-2].+2).*aux)\n",
    "    J[1,1] = 0.0; J = J + J'\n",
    "\n",
    "    D, V = eigen(J)\n",
    "    i = sortperm(D); x = [-1.0; D[i]; 1.0]\n",
    "    x\n",
    "end\n",
    "\n",
    "function legendre(x,m)\n",
    "    # Evaluate orhonormal m'th order Legendre Polynomial at point x\n",
    "    xp = x\n",
    "    # Initial values P_0(x) and P_1(x)\n",
    "    PL = zeros(m+1, length(xp))\n",
    "    PL[1,:]  .= sqrt(1.0/2.0)\n",
    "    if  m == 0\n",
    "        P = PL'\n",
    "        return P\n",
    "    end\n",
    "    PL[2,:] = sqrt(3.0/2.0)*xp\n",
    "    if  m == 1\n",
    "        P = PL[m+1,:]\n",
    "        return P\n",
    "    end\n",
    "\n",
    "    # Forward recurrence using the symmetry of the recurrence.\n",
    "    aold = sqrt(1.0/3.0)\n",
    "    for i=1:m-1\n",
    "        anew = 2/(2*i+2)*sqrt((i+1)*(i+1)*(i+1)*(i+1)/(2*i+1)/(2*i+3))\n",
    "        PL[i+2,:] = 1/anew*(-aold*PL[i,:] + xp.*PL[i+1,:])\n",
    "        aold = anew\n",
    "    end\n",
    "    P = PL[m+1,:]\n",
    "    return P\n",
    "end\n",
    "\n",
    "function vandermonde(m,r)\n",
    "    # Initialize the 1D Vandermonde Matrix, V_{ij} = phi_j(r_i)\n",
    "    V = zeros(length(r),m+1)\n",
    "    for j in 1:m+1\n",
    "        V[:,j] = legendre(r, j-1)\n",
    "    end\n",
    "    V\n",
    "end\n",
    "\n",
    "function gradlegendre(r, m)\n",
    "    \"\"\"\n",
    "    Evaluate the derivative of the\n",
    "    m'th order Legendre polynomial at points r\n",
    "    \"\"\"\n",
    "    dP = zeros(length(r),1)\n",
    "    if m>0\n",
    "        Ph = -m*r.*legendre(r,m) + m*sqrt((2*m+1)/(2*m-1))*legendre(r,m-1)\n",
    "        dPe = r.^(m+1)*m*(m+1)/2*sqrt((2*m+1)/2)\n",
    "        endp = (broadcast(abs, broadcast(abs,r).-1)) .> 10*2.2204e-16\n",
    "        rh = r.*endp\n",
    "        dP = broadcast(~,endp).*dPe + endp.*Ph./(1.0 .- rh.^2)\n",
    "    end\n",
    "    dP\n",
    "end\n",
    "\n",
    "function dmatrix(m,r,V)\n",
    "    \"\"\"\n",
    "    Purpose : Initialize the (r) differentiation matrices,\n",
    "    evaluated at (r) at order m\n",
    "    \"\"\"\n",
    "    Vr = zeros(length(r),m+1)\n",
    "    for i=0:m\n",
    "       Vr[:,i+1] = gradlegendre(r,i)\n",
    "    end\n",
    "    D = Vr/V\n",
    "    D\n",
    "end"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 问题定义"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "rhs (generic function with 1 method)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function rhs(u,p,t)\n",
    "    D, Φ, h, α, du, q, dq = p\n",
    "    \n",
    "    # Define u field differences at faces\n",
    "    du[1,2:end]     = (α/2.0 - 1)*(u[1,2:end]-u[end,1:end-1]) \n",
    "    du[end,1:end-1] = α/2.0*(u[end,1:end-1]-u[1,2:end])\n",
    "\n",
    "    # Impose boundary condition\n",
    "    uin  = - u[1,1]\n",
    "    uout = - u[end,end]\n",
    "    du[1,1] = (α/2.0 - 1)*(u[1,1] - uin)\n",
    "    du[end,end] = α/2.0*(u[end,end] - uout)\n",
    "    \n",
    "    # Compute q \n",
    "    q = -2.0/h*(D*u .- Φ*du) \n",
    "    \n",
    "    # Define q field differences at faces\n",
    "    dq[1,2:end]     = (α/2.0 - 1)*(q[1,2:end]-q[end,1:end-1]) \n",
    "    dq[end,1:end-1] = α/2.0*(q[end,1:end-1]-q[1,2:end])\n",
    "    \n",
    "    # Impose boundary condition\n",
    "    qin  = q[1,1]\n",
    "    qout = q[end,end]\n",
    "    dq[1,1] = (α/2.0 - 1)*(q[1,1] - qin)\n",
    "    dq[end,end] = α/2.0*(q[end,end] - qout)\n",
    "    \n",
    "    return -2.0/h*(D*q .- Φ*dq) \n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3×100 Array{Float64,2}:\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  …  0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0\n",
       " 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p = 2      # order of polynomials\n",
    "Np = p+1   # number of points\n",
    "K = 100    # number of elements\n",
    "xmin = 0\n",
    "xmax = 2π\n",
    "L = xmax - xmin\n",
    "h = L/K\n",
    "r = legendregausslobatto(p)\n",
    "VX = [xmin + i * h for i = 0:K]\n",
    "@inbounds x = ones(p + 1, 1) * VX[1:K]' + 0.5 * (r .+ 1) * (VX[2:K+1] - VX[1:K])'\n",
    "@inbounds V = vandermonde(p, r)\n",
    "@inbounds D = dmatrix(p, r, V)\n",
    "@inbounds Φ = V * V'\n",
    "@inbounds u0 = sin.(x) \n",
    "q  = zeros(Np, K)\n",
    "du = zeros(Np, K)\n",
    "dq = zeros(Np, K)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  0.681950 seconds (777.85 k allocations: 1.293 GiB, 33.31% gc time)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "1.157025418563407e-5"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tspan = (0.0, 0.8)\n",
    "prob = ODEProblem(rhs, u0, tspan, (D, Φ, h, 1, du, q, dq))\n",
    "@time uf = solve(prob,Tsit5(),save_everystep=false)\n",
    "error = norm(uf[2] - exp(-tspan[2])*sin.(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"600\" height=\"400\" viewBox=\"0 0 2400 1600\">\n",
       "<defs>\n",
       "  <clipPath id=\"clip3500\">\n",
       "    <rect x=\"0\" y=\"0\" width=\"2400\" height=\"1600\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<path clip-path=\"url(#clip3500)\" d=\"\n",
       "M0 1600 L2400 1600 L2400 0 L0 0  Z\n",
       "  \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
       "<defs>\n",
       "  <clipPath id=\"clip3501\">\n",
       "    <rect x=\"480\" y=\"0\" width=\"1681\" height=\"1600\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<path clip-path=\"url(#clip3500)\" d=\"\n",
       "M208.77 1487.47 L2352.76 1487.47 L2352.76 47.2441 L208.77 47.2441  Z\n",
       "  \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
       "<defs>\n",
       "  <clipPath id=\"clip3502\">\n",
       "    <rect x=\"208\" y=\"47\" width=\"2145\" height=\"1441\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<polyline clip-path=\"url(#clip3502)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  269.449,1487.47 269.449,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3502)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  591.36,1487.47 591.36,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3502)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  913.272,1487.47 913.272,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3502)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  1235.18,1487.47 1235.18,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3502)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  1557.09,1487.47 1557.09,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3502)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  1879.01,1487.47 1879.01,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3502)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  2200.92,1487.47 2200.92,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3502)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  208.77,1487.47 2352.76,1487.47 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3502)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  208.77,1127.42 2352.76,1127.42 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3502)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  208.77,767.359 2352.76,767.359 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3502)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  208.77,407.302 2352.76,407.302 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3502)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  208.77,47.2441 2352.76,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3500)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  208.77,1487.47 2352.76,1487.47 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3500)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  208.77,1487.47 208.77,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3500)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  269.449,1487.47 269.449,1470.19 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3500)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  591.36,1487.47 591.36,1470.19 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3500)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  913.272,1487.47 913.272,1470.19 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3500)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1235.18,1487.47 1235.18,1470.19 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3500)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1557.09,1487.47 1557.09,1470.19 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3500)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1879.01,1487.47 1879.01,1470.19 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3500)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  2200.92,1487.47 2200.92,1470.19 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3500)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  208.77,1487.47 234.498,1487.47 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3500)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  208.77,1127.42 234.498,1127.42 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3500)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  208.77,767.359 234.498,767.359 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3500)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  208.77,407.302 234.498,407.302 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3500)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  208.77,47.2441 234.498,47.2441 \n",
       "  \"/>\n",
       "<g clip-path=\"url(#clip3500)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 269.449, 1541.47)\" x=\"269.449\" y=\"1541.47\">0</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip3500)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 591.36, 1541.47)\" x=\"591.36\" y=\"1541.47\">1</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip3500)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 913.272, 1541.47)\" x=\"913.272\" y=\"1541.47\">2</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip3500)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 1235.18, 1541.47)\" x=\"1235.18\" y=\"1541.47\">3</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip3500)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 1557.09, 1541.47)\" x=\"1557.09\" y=\"1541.47\">4</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip3500)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 1879.01, 1541.47)\" x=\"1879.01\" y=\"1541.47\">5</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip3500)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 2200.92, 1541.47)\" x=\"2200.92\" y=\"1541.47\">6</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip3500)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 184.77, 1504.97)\" x=\"184.77\" y=\"1504.97\">-0.50</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip3500)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 184.77, 1144.92)\" x=\"184.77\" y=\"1144.92\">-0.25</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip3500)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 184.77, 784.859)\" x=\"184.77\" y=\"784.859\">0.00</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip3500)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 184.77, 424.802)\" x=\"184.77\" y=\"424.802\">0.25</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip3500)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 184.77, 64.7441)\" x=\"184.77\" y=\"64.7441\">0.50</text>\n",
       "</g>\n",
       "<polyline clip-path=\"url(#clip3502)\" style=\"stroke:#009af9; stroke-width:12; stroke-opacity:1; fill:none\" points=\"\n",
       "  269.449,767.361 279.562,747.032 289.676,726.724 289.676,726.727 299.789,706.458 309.902,686.251 309.902,686.253 320.015,666.125 330.128,646.097 330.128,646.1 \n",
       "  340.241,626.191 350.354,606.422 350.354,606.424 360.467,586.814 370.581,567.382 370.581,567.384 380.694,548.15 390.807,529.131 390.807,529.133 400.92,510.35 \n",
       "  411.033,491.82 411.033,491.822 421.146,473.565 431.259,455.597 431.259,455.6 441.373,437.94 451.486,420.604 451.486,420.607 461.599,403.614 471.712,386.98 \n",
       "  471.712,386.983 481.825,370.724 491.938,354.858 491.938,354.86 502.051,339.4 512.165,324.363 512.165,324.365 522.278,309.764 532.391,295.616 532.391,295.618 \n",
       "  542.504,281.934 552.617,268.731 552.617,268.732 562.73,256.021 572.843,243.814 572.843,243.815 582.957,232.125 593.07,220.963 593.07,220.963 603.183,210.341 \n",
       "  613.296,200.268 613.296,200.269 623.409,190.756 633.522,181.811 633.522,181.812 643.635,173.446 653.749,165.665 653.749,165.667 663.862,158.48 673.975,151.895 \n",
       "  673.975,151.896 684.088,145.917 694.201,140.553 694.201,140.554 704.314,135.807 714.427,131.685 714.427,131.685 724.54,128.189 734.654,125.325 734.654,125.325 \n",
       "  744.767,123.094 754.88,121.5 754.88,121.499 764.993,120.541 775.106,120.222 775.106,120.221 785.219,120.542 795.332,121.499 795.332,121.498 805.446,123.094 \n",
       "  815.559,125.325 815.559,125.324 825.672,128.19 835.785,131.684 835.785,131.684 845.898,135.807 856.011,140.553 856.011,140.553 866.124,145.917 876.238,151.895 \n",
       "  876.238,151.896 886.351,158.48 896.464,165.667 896.464,165.667 906.577,173.446 916.69,181.813 916.69,181.812 926.803,190.756 936.916,200.27 936.916,200.268 \n",
       "  947.03,210.341 957.143,220.965 957.143,220.962 967.256,232.125 977.369,243.815 977.369,243.813 987.482,256.021 997.595,268.732 997.595,268.73 1007.71,281.935 \n",
       "  1017.82,295.617 1017.82,295.615 1027.93,309.764 1038.05,324.364 1038.05,324.362 1048.16,339.4 1058.27,354.859 1058.27,354.858 1068.39,370.724 1078.5,386.982 \n",
       "  1078.5,386.981 1088.61,403.614 1098.73,420.607 1098.73,420.606 1108.84,437.939 1118.95,455.6 1118.95,455.598 1129.07,473.565 1139.18,491.824 1139.18,491.821 \n",
       "  1149.29,510.35 1159.41,529.134 1159.41,529.131 1169.52,548.149 1179.63,567.385 1179.63,567.381 1189.74,586.814 1199.86,606.424 1199.86,606.421 1209.97,626.191 \n",
       "  1220.08,646.099 1220.08,646.096 1230.2,666.125 1240.31,686.252 1240.31,686.25 1250.42,706.459 1260.54,726.726 1260.54,726.724 1270.65,747.032 1280.76,767.36 \n",
       "  1280.76,767.359 1290.88,787.686 1300.99,807.995 1300.99,807.993 1311.1,828.26 1321.22,848.469 1321.22,848.467 1331.33,868.594 1341.44,888.623 1341.44,888.62 \n",
       "  1351.56,908.528 1361.67,928.298 1361.67,928.294 1371.78,947.905 1381.89,967.338 1381.89,967.334 1392.01,986.57 1402.12,1005.59 1402.12,1005.58 1412.23,1024.37 \n",
       "  1422.35,1042.9 1422.35,1042.9 1432.46,1061.15 1442.57,1079.12 1442.57,1079.12 1452.69,1096.78 1462.8,1114.11 1462.8,1114.11 1472.91,1131.1 1483.03,1147.74 \n",
       "  1483.03,1147.74 1493.14,1163.99 1503.25,1179.86 1503.25,1179.86 1513.37,1195.32 1523.48,1210.36 1523.48,1210.36 1533.59,1224.95 1543.7,1239.1 1543.7,1239.1 \n",
       "  1553.82,1252.78 1563.93,1265.99 1563.93,1265.99 1574.04,1278.7 1584.16,1290.91 1584.16,1290.9 1594.27,1302.59 1604.38,1313.76 1604.38,1313.75 1614.5,1324.38 \n",
       "  1624.61,1334.45 1624.61,1334.45 1634.72,1343.96 1644.84,1352.91 1644.84,1352.91 1654.95,1361.27 1665.06,1369.05 1665.06,1369.05 1675.18,1376.24 1685.29,1382.82 \n",
       "  1685.29,1382.82 1695.4,1388.8 1705.51,1394.17 1705.51,1394.17 1715.63,1398.91 1725.74,1403.04 1725.74,1403.03 1735.85,1406.53 1745.97,1409.4 1745.97,1409.39 \n",
       "  1756.08,1411.62 1766.19,1413.22 1766.19,1413.22 1776.31,1414.18 1786.42,1414.5 1786.42,1414.5 1796.53,1414.18 1806.65,1413.22 1806.65,1413.22 1816.76,1411.63 \n",
       "  1826.87,1409.39 1826.87,1409.39 1836.99,1406.53 1847.1,1403.03 1847.1,1403.03 1857.21,1398.91 1867.33,1394.16 1867.33,1394.17 1877.44,1388.8 1887.55,1382.82 \n",
       "  1887.55,1382.82 1897.66,1376.24 1907.78,1369.05 1907.78,1369.05 1917.89,1361.27 1928,1352.91 1928,1352.91 1938.12,1343.96 1948.23,1334.45 1948.23,1334.45 \n",
       "  1958.34,1324.38 1968.46,1313.76 1968.46,1313.76 1978.57,1302.59 1988.68,1290.9 1988.68,1290.9 1998.8,1278.7 2008.91,1265.99 2008.91,1265.99 2019.02,1252.78 \n",
       "  2029.14,1239.1 2029.14,1239.1 2039.25,1224.96 2049.36,1210.35 2049.36,1210.36 2059.47,1195.32 2069.59,1179.86 2069.59,1179.86 2079.7,1163.99 2089.81,1147.74 \n",
       "  2089.81,1147.74 2099.93,1131.1 2110.04,1114.11 2110.04,1114.12 2120.15,1096.78 2130.27,1079.12 2130.27,1079.12 2140.38,1061.15 2150.49,1042.9 2150.49,1042.9 \n",
       "  2160.61,1024.37 2170.72,1005.59 2170.72,1005.59 2180.83,986.569 2190.95,967.335 2190.95,967.336 2201.06,947.905 2211.17,928.295 2211.17,928.296 2221.29,908.528 \n",
       "  2231.4,888.619 2231.4,888.621 2241.51,868.594 2251.62,848.465 2251.62,848.468 2261.74,828.261 2271.85,807.991 2271.85,807.995 2281.96,787.687 2292.08,767.357 \n",
       "  \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3502)\" style=\"stroke:#e26f46; stroke-width:12; stroke-opacity:1; fill:none\" stroke-dasharray=\"48, 30\" points=\"\n",
       "  269.449,767.359 279.562,747.032 289.676,726.725 299.789,706.458 309.902,686.252 320.015,666.125 330.128,646.098 \n",
       "  340.241,626.191 350.354,606.423 360.467,586.814 370.581,567.383 380.694,548.149 390.807,529.132 400.92,510.35 \n",
       "  411.033,491.822 421.146,473.565 431.259,455.599 441.373,437.94 451.486,420.606 461.599,403.614 471.712,386.982 \n",
       "  481.825,370.724 491.938,354.859 502.051,339.4 512.165,324.363 522.278,309.764 532.391,295.617 \n",
       "  542.504,281.935 552.617,268.732 562.73,256.021 572.843,243.814 582.957,232.125 593.07,220.963 603.183,210.341 \n",
       "  613.296,200.269 623.409,190.756 633.522,181.812 643.635,173.446 653.749,165.666 663.862,158.48 673.975,151.895 \n",
       "  684.088,145.918 694.201,140.553 704.314,135.807 714.427,131.685 724.54,128.189 734.654,125.325 \n",
       "  744.767,123.094 754.88,121.499 764.993,120.541 775.106,120.222 785.219,120.541 795.332,121.499 805.446,123.094 \n",
       "  815.559,125.325 825.672,128.189 835.785,131.685 845.898,135.807 856.011,140.553 866.124,145.918 876.238,151.895 \n",
       "  886.351,158.48 896.464,165.666 906.577,173.446 916.69,181.812 926.803,190.756 936.916,200.269 \n",
       "  947.03,210.341 957.143,220.963 967.256,232.125 977.369,243.814 987.482,256.021 997.595,268.732 1007.71,281.935 \n",
       "  1017.82,295.617 1027.93,309.764 1038.05,324.363 1048.16,339.4 1058.27,354.859 1068.39,370.724 1078.5,386.982 \n",
       "  1088.61,403.614 1098.73,420.606 1108.84,437.94 1118.95,455.599 1129.07,473.565 1139.18,491.822 \n",
       "  1149.29,510.35 1159.41,529.132 1169.52,548.149 1179.63,567.383 1189.74,586.814 1199.86,606.423 1209.97,626.191 \n",
       "  1220.08,646.098 1230.2,666.125 1240.31,686.252 1250.42,706.458 1260.54,726.725 1270.65,747.032 1280.76,767.359 \n",
       "  1290.88,787.686 1300.99,807.994 1311.1,828.26 1321.22,848.467 1331.33,868.594 1341.44,888.621 \n",
       "  1351.56,908.528 1361.67,928.296 1371.78,947.905 1381.89,967.336 1392.01,986.569 1402.12,1005.59 1412.23,1024.37 \n",
       "  1422.35,1042.9 1432.46,1061.15 1442.57,1079.12 1452.69,1096.78 1462.8,1114.11 1472.91,1131.1 1483.03,1147.74 \n",
       "  1493.14,1163.99 1503.25,1179.86 1513.37,1195.32 1523.48,1210.36 1533.59,1224.95 1543.7,1239.1 \n",
       "  1553.82,1252.78 1563.93,1265.99 1574.04,1278.7 1584.16,1290.9 1594.27,1302.59 1604.38,1313.76 1614.5,1324.38 \n",
       "  1624.61,1334.45 1634.72,1343.96 1644.84,1352.91 1654.95,1361.27 1665.06,1369.05 1675.18,1376.24 1685.29,1382.82 \n",
       "  1695.4,1388.8 1705.51,1394.17 1715.63,1398.91 1725.74,1403.03 1735.85,1406.53 1745.97,1409.39 \n",
       "  1756.08,1411.62 1766.19,1413.22 1776.31,1414.18 1786.42,1414.5 1796.53,1414.18 1806.65,1413.22 1816.76,1411.62 \n",
       "  1826.87,1409.39 1836.99,1406.53 1847.1,1403.03 1857.21,1398.91 1867.33,1394.17 1877.44,1388.8 1887.55,1382.82 \n",
       "  1897.66,1376.24 1907.78,1369.05 1917.89,1361.27 1928,1352.91 1938.12,1343.96 1948.23,1334.45 \n",
       "  1958.34,1324.38 1968.46,1313.76 1978.57,1302.59 1988.68,1290.9 1998.8,1278.7 2008.91,1265.99 2019.02,1252.78 \n",
       "  2029.14,1239.1 2039.25,1224.95 2049.36,1210.36 2059.47,1195.32 2069.59,1179.86 2079.7,1163.99 2089.81,1147.74 \n",
       "  2099.93,1131.1 2110.04,1114.11 2120.15,1096.78 2130.27,1079.12 2140.38,1061.15 2150.49,1042.9 \n",
       "  2160.61,1024.37 2170.72,1005.59 2180.83,986.569 2190.95,967.336 2201.06,947.905 2211.17,928.296 2221.29,908.528 \n",
       "  2231.4,888.621 2241.51,868.594 2251.62,848.467 2261.74,828.26 2271.85,807.994 2281.96,787.686 2292.08,767.359 \n",
       "  \n",
       "  \"/>\n",
       "<path clip-path=\"url(#clip3500)\" d=\"\n",
       "M1989.93 312.204 L2280.76 312.204 L2280.76 130.764 L1989.93 130.764  Z\n",
       "  \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
       "<polyline clip-path=\"url(#clip3500)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1989.93,312.204 2280.76,312.204 2280.76,130.764 1989.93,130.764 1989.93,312.204 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip3500)\" style=\"stroke:#009af9; stroke-width:12; stroke-opacity:1; fill:none\" points=\"\n",
       "  2013.93,191.244 2157.93,191.244 \n",
       "  \"/>\n",
       "<g clip-path=\"url(#clip3500)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:start;\" transform=\"rotate(0, 2181.93, 208.744)\" x=\"2181.93\" y=\"208.744\">y1</text>\n",
       "</g>\n",
       "<polyline clip-path=\"url(#clip3500)\" style=\"stroke:#e26f46; stroke-width:12; stroke-opacity:1; fill:none\" stroke-dasharray=\"48, 30\" points=\"\n",
       "  2013.93,251.724 2157.93,251.724 \n",
       "  \"/>\n",
       "<g clip-path=\"url(#clip3500)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:start;\" transform=\"rotate(0, 2181.93, 269.224)\" x=\"2181.93\" y=\"269.224\">y2</text>\n",
       "</g>\n",
       "</svg>\n"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plot(x[:],uf[2][:],ylims = (-0.5,0.5),lw=3)\n",
    "plot!(x[:],(exp(-tspan[2])*sin.(x))[:],ylims = (-0.5,0.5),ls=:dash,lw=3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  0.001238 seconds (2.14 k allocations: 2.200 MiB)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0.22287578970561592"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tspan = (0.0, 0.8)\n",
    "prob = ODEProblem(rhs, u0, tspan, (D, Φ, h, 1, du, q, dq))\n",
    "@time uf = solve(prob,CVODE_BDF(linear_solver=:GMRES),save_everystep=false)\n",
    "error = norm(uf[2] - exp(-tspan[2])*sin.(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"600\" height=\"400\" viewBox=\"0 0 2400 1600\">\n",
       "<defs>\n",
       "  <clipPath id=\"clip4300\">\n",
       "    <rect x=\"0\" y=\"0\" width=\"2400\" height=\"1600\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<path clip-path=\"url(#clip4300)\" d=\"\n",
       "M0 1600 L2400 1600 L2400 0 L0 0  Z\n",
       "  \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
       "<defs>\n",
       "  <clipPath id=\"clip4301\">\n",
       "    <rect x=\"480\" y=\"0\" width=\"1681\" height=\"1600\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<path clip-path=\"url(#clip4300)\" d=\"\n",
       "M208.77 1487.47 L2352.76 1487.47 L2352.76 47.2441 L208.77 47.2441  Z\n",
       "  \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
       "<defs>\n",
       "  <clipPath id=\"clip4302\">\n",
       "    <rect x=\"208\" y=\"47\" width=\"2145\" height=\"1441\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<polyline clip-path=\"url(#clip4302)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  269.449,1487.47 269.449,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4302)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  591.36,1487.47 591.36,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4302)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  913.272,1487.47 913.272,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4302)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  1235.18,1487.47 1235.18,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4302)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  1557.09,1487.47 1557.09,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4302)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  1879.01,1487.47 1879.01,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4302)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  2200.92,1487.47 2200.92,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4302)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  208.77,1487.47 2352.76,1487.47 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4302)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  208.77,1127.42 2352.76,1127.42 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4302)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  208.77,767.359 2352.76,767.359 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4302)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  208.77,407.302 2352.76,407.302 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4302)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  208.77,47.2441 2352.76,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4300)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  208.77,1487.47 2352.76,1487.47 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4300)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  208.77,1487.47 208.77,47.2441 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4300)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  269.449,1487.47 269.449,1470.19 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4300)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  591.36,1487.47 591.36,1470.19 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4300)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  913.272,1487.47 913.272,1470.19 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4300)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1235.18,1487.47 1235.18,1470.19 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4300)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1557.09,1487.47 1557.09,1470.19 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4300)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1879.01,1487.47 1879.01,1470.19 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4300)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  2200.92,1487.47 2200.92,1470.19 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4300)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  208.77,1487.47 234.498,1487.47 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4300)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  208.77,1127.42 234.498,1127.42 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4300)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  208.77,767.359 234.498,767.359 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4300)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  208.77,407.302 234.498,407.302 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4300)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  208.77,47.2441 234.498,47.2441 \n",
       "  \"/>\n",
       "<g clip-path=\"url(#clip4300)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 269.449, 1541.47)\" x=\"269.449\" y=\"1541.47\">0</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip4300)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 591.36, 1541.47)\" x=\"591.36\" y=\"1541.47\">1</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip4300)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 913.272, 1541.47)\" x=\"913.272\" y=\"1541.47\">2</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip4300)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 1235.18, 1541.47)\" x=\"1235.18\" y=\"1541.47\">3</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip4300)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 1557.09, 1541.47)\" x=\"1557.09\" y=\"1541.47\">4</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip4300)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 1879.01, 1541.47)\" x=\"1879.01\" y=\"1541.47\">5</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip4300)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 2200.92, 1541.47)\" x=\"2200.92\" y=\"1541.47\">6</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip4300)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 184.77, 1504.97)\" x=\"184.77\" y=\"1504.97\">-0.50</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip4300)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 184.77, 1144.92)\" x=\"184.77\" y=\"1144.92\">-0.25</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip4300)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 184.77, 784.859)\" x=\"184.77\" y=\"784.859\">0.00</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip4300)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 184.77, 424.802)\" x=\"184.77\" y=\"424.802\">0.25</text>\n",
       "</g>\n",
       "<g clip-path=\"url(#clip4300)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 184.77, 64.7441)\" x=\"184.77\" y=\"64.7441\">0.50</text>\n",
       "</g>\n",
       "<polyline clip-path=\"url(#clip4302)\" style=\"stroke:#009af9; stroke-width:12; stroke-opacity:1; fill:none\" points=\"\n",
       "  269.449,767.361 279.562,747.856 289.676,728.37 289.676,728.372 299.789,708.925 309.902,689.535 309.902,689.538 320.015,670.225 330.128,651.008 330.128,651.01 \n",
       "  340.241,631.908 350.354,612.939 350.354,612.942 360.467,594.126 370.581,575.481 370.581,575.483 380.694,557.028 390.807,538.779 390.807,538.781 400.92,520.759 \n",
       "  411.033,502.98 411.033,502.982 421.146,485.464 431.259,468.223 431.259,468.226 441.373,451.282 451.486,434.648 451.486,434.65 461.599,418.347 471.712,402.385 \n",
       "  471.712,402.388 481.825,386.789 491.938,371.563 491.938,371.565 502.051,356.733 512.165,342.303 512.165,342.305 522.278,328.298 532.391,314.721 532.391,314.723 \n",
       "  542.504,301.595 552.617,288.925 552.617,288.926 562.73,276.731 572.843,265.017 572.843,265.018 582.957,253.803 593.07,243.091 593.07,243.092 603.183,232.901 \n",
       "  613.296,223.235 613.296,223.236 623.409,214.109 633.522,205.525 633.522,205.527 643.635,197.501 653.749,190.034 653.749,190.035 663.862,183.141 673.975,176.82 \n",
       "  673.975,176.821 684.088,171.087 694.201,165.938 694.201,165.938 704.314,161.386 714.427,157.429 714.427,157.429 724.54,154.077 734.654,151.326 734.654,151.327 \n",
       "  744.767,149.188 754.88,147.656 754.88,147.656 764.993,146.739 775.106,146.43 775.106,146.43 785.219,146.739 795.332,147.656 795.332,147.656 805.446,149.188 \n",
       "  815.559,151.327 815.559,151.326 825.672,154.077 835.785,157.429 835.785,157.429 845.898,161.386 856.011,165.938 856.011,165.938 866.124,171.087 876.238,176.821 \n",
       "  876.238,176.82 886.351,183.141 896.464,190.035 896.464,190.034 906.577,197.501 916.69,205.527 916.69,205.526 926.803,214.109 936.916,223.236 936.916,223.235 \n",
       "  947.03,232.901 957.143,243.092 957.143,243.091 967.256,253.803 977.369,265.018 977.369,265.016 987.482,276.731 997.595,288.926 997.595,288.925 1007.71,301.595 \n",
       "  1017.82,314.723 1017.82,314.721 1027.93,328.298 1038.05,342.305 1038.05,342.303 1048.16,356.733 1058.27,371.565 1058.27,371.563 1068.39,386.789 1078.5,402.388 \n",
       "  1078.5,402.385 1088.61,418.347 1098.73,434.65 1098.73,434.648 1108.84,451.282 1118.95,468.226 1118.95,468.223 1129.07,485.464 1139.18,502.982 1139.18,502.979 \n",
       "  1149.29,520.76 1159.41,538.781 1159.41,538.779 1169.52,557.028 1179.63,575.483 1179.63,575.481 1189.74,594.126 1199.86,612.942 1199.86,612.939 1209.97,631.908 \n",
       "  1220.08,651.01 1220.08,651.008 1230.2,670.225 1240.31,689.538 1240.31,689.535 1250.42,708.925 1260.54,728.372 1260.54,728.37 1270.65,747.856 1280.76,767.361 \n",
       "  1280.76,767.358 1290.88,786.863 1300.99,806.349 1300.99,806.347 1311.1,825.794 1321.22,845.184 1321.22,845.181 1331.33,864.494 1341.44,883.711 1341.44,883.709 \n",
       "  1351.56,902.811 1361.67,921.779 1361.67,921.777 1371.78,940.593 1381.89,959.238 1381.89,959.236 1392.01,977.691 1402.12,995.94 1402.12,995.937 1412.23,1013.96 \n",
       "  1422.35,1031.74 1422.35,1031.74 1432.46,1049.25 1442.57,1066.5 1442.57,1066.49 1452.69,1083.44 1462.8,1100.07 1462.8,1100.07 1472.91,1116.37 1483.03,1132.33 \n",
       "  1483.03,1132.33 1493.14,1147.93 1503.25,1163.16 1503.25,1163.15 1513.37,1177.99 1523.48,1192.42 1523.48,1192.41 1533.59,1206.42 1543.7,1220 1543.7,1220 \n",
       "  1553.82,1233.12 1563.93,1245.79 1563.93,1245.79 1574.04,1257.99 1584.16,1269.7 1584.16,1269.7 1594.27,1280.92 1604.38,1291.63 1604.38,1291.63 1614.5,1301.82 \n",
       "  1624.61,1311.48 1624.61,1311.48 1634.72,1320.61 1644.84,1329.19 1644.84,1329.19 1654.95,1337.22 1665.06,1344.69 1665.06,1344.68 1675.18,1351.58 1685.29,1357.9 \n",
       "  1685.29,1357.9 1695.4,1363.63 1705.51,1368.78 1705.51,1368.78 1715.63,1373.33 1725.74,1377.29 1725.74,1377.29 1735.85,1380.64 1745.97,1383.39 1745.97,1383.39 \n",
       "  1756.08,1385.53 1766.19,1387.06 1766.19,1387.06 1776.31,1387.98 1786.42,1388.29 1786.42,1388.29 1796.53,1387.98 1806.65,1387.06 1806.65,1387.06 1816.76,1385.53 \n",
       "  1826.87,1383.39 1826.87,1383.39 1836.99,1380.64 1847.1,1377.29 1847.1,1377.29 1857.21,1373.33 1867.33,1368.78 1867.33,1368.78 1877.44,1363.63 1887.55,1357.9 \n",
       "  1887.55,1357.9 1897.66,1351.58 1907.78,1344.68 1907.78,1344.69 1917.89,1337.22 1928,1329.19 1928,1329.19 1938.12,1320.61 1948.23,1311.48 1948.23,1311.48 \n",
       "  1958.34,1301.82 1968.46,1291.63 1968.46,1291.63 1978.57,1280.92 1988.68,1269.7 1988.68,1269.7 1998.8,1257.99 2008.91,1245.79 2008.91,1245.79 2019.02,1233.12 \n",
       "  2029.14,1220 2029.14,1220 2039.25,1206.42 2049.36,1192.41 2049.36,1192.42 2059.47,1177.99 2069.59,1163.15 2069.59,1163.16 2079.7,1147.93 2089.81,1132.33 \n",
       "  2089.81,1132.33 2099.93,1116.37 2110.04,1100.07 2110.04,1100.07 2120.15,1083.44 2130.27,1066.49 2130.27,1066.5 2140.38,1049.25 2150.49,1031.74 2150.49,1031.74 \n",
       "  2160.61,1013.96 2170.72,995.938 2170.72,995.94 2180.83,977.691 2190.95,959.236 2190.95,959.238 2201.06,940.592 2211.17,921.777 2211.17,921.779 2221.29,902.811 \n",
       "  2231.4,883.709 2231.4,883.711 2241.51,864.494 2251.62,845.181 2251.62,845.184 2261.74,825.794 2271.85,806.347 2271.85,806.349 2281.96,786.863 2292.08,767.358 \n",
       "  \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4302)\" style=\"stroke:#e26f46; stroke-width:12; stroke-opacity:1; fill:none\" stroke-dasharray=\"48, 30\" points=\"\n",
       "  269.449,767.359 279.562,747.032 289.676,726.725 299.789,706.458 309.902,686.252 320.015,666.125 330.128,646.098 \n",
       "  340.241,626.191 350.354,606.423 360.467,586.814 370.581,567.383 380.694,548.149 390.807,529.132 400.92,510.35 \n",
       "  411.033,491.822 421.146,473.565 431.259,455.599 441.373,437.94 451.486,420.606 461.599,403.614 471.712,386.982 \n",
       "  481.825,370.724 491.938,354.859 502.051,339.4 512.165,324.363 522.278,309.764 532.391,295.617 \n",
       "  542.504,281.935 552.617,268.732 562.73,256.021 572.843,243.814 582.957,232.125 593.07,220.963 603.183,210.341 \n",
       "  613.296,200.269 623.409,190.756 633.522,181.812 643.635,173.446 653.749,165.666 663.862,158.48 673.975,151.895 \n",
       "  684.088,145.918 694.201,140.553 704.314,135.807 714.427,131.685 724.54,128.189 734.654,125.325 \n",
       "  744.767,123.094 754.88,121.499 764.993,120.541 775.106,120.222 785.219,120.541 795.332,121.499 805.446,123.094 \n",
       "  815.559,125.325 825.672,128.189 835.785,131.685 845.898,135.807 856.011,140.553 866.124,145.918 876.238,151.895 \n",
       "  886.351,158.48 896.464,165.666 906.577,173.446 916.69,181.812 926.803,190.756 936.916,200.269 \n",
       "  947.03,210.341 957.143,220.963 967.256,232.125 977.369,243.814 987.482,256.021 997.595,268.732 1007.71,281.935 \n",
       "  1017.82,295.617 1027.93,309.764 1038.05,324.363 1048.16,339.4 1058.27,354.859 1068.39,370.724 1078.5,386.982 \n",
       "  1088.61,403.614 1098.73,420.606 1108.84,437.94 1118.95,455.599 1129.07,473.565 1139.18,491.822 \n",
       "  1149.29,510.35 1159.41,529.132 1169.52,548.149 1179.63,567.383 1189.74,586.814 1199.86,606.423 1209.97,626.191 \n",
       "  1220.08,646.098 1230.2,666.125 1240.31,686.252 1250.42,706.458 1260.54,726.725 1270.65,747.032 1280.76,767.359 \n",
       "  1290.88,787.686 1300.99,807.994 1311.1,828.26 1321.22,848.467 1331.33,868.594 1341.44,888.621 \n",
       "  1351.56,908.528 1361.67,928.296 1371.78,947.905 1381.89,967.336 1392.01,986.569 1402.12,1005.59 1412.23,1024.37 \n",
       "  1422.35,1042.9 1432.46,1061.15 1442.57,1079.12 1452.69,1096.78 1462.8,1114.11 1472.91,1131.1 1483.03,1147.74 \n",
       "  1493.14,1163.99 1503.25,1179.86 1513.37,1195.32 1523.48,1210.36 1533.59,1224.95 1543.7,1239.1 \n",
       "  1553.82,1252.78 1563.93,1265.99 1574.04,1278.7 1584.16,1290.9 1594.27,1302.59 1604.38,1313.76 1614.5,1324.38 \n",
       "  1624.61,1334.45 1634.72,1343.96 1644.84,1352.91 1654.95,1361.27 1665.06,1369.05 1675.18,1376.24 1685.29,1382.82 \n",
       "  1695.4,1388.8 1705.51,1394.17 1715.63,1398.91 1725.74,1403.03 1735.85,1406.53 1745.97,1409.39 \n",
       "  1756.08,1411.62 1766.19,1413.22 1776.31,1414.18 1786.42,1414.5 1796.53,1414.18 1806.65,1413.22 1816.76,1411.62 \n",
       "  1826.87,1409.39 1836.99,1406.53 1847.1,1403.03 1857.21,1398.91 1867.33,1394.17 1877.44,1388.8 1887.55,1382.82 \n",
       "  1897.66,1376.24 1907.78,1369.05 1917.89,1361.27 1928,1352.91 1938.12,1343.96 1948.23,1334.45 \n",
       "  1958.34,1324.38 1968.46,1313.76 1978.57,1302.59 1988.68,1290.9 1998.8,1278.7 2008.91,1265.99 2019.02,1252.78 \n",
       "  2029.14,1239.1 2039.25,1224.95 2049.36,1210.36 2059.47,1195.32 2069.59,1179.86 2079.7,1163.99 2089.81,1147.74 \n",
       "  2099.93,1131.1 2110.04,1114.11 2120.15,1096.78 2130.27,1079.12 2140.38,1061.15 2150.49,1042.9 \n",
       "  2160.61,1024.37 2170.72,1005.59 2180.83,986.569 2190.95,967.336 2201.06,947.905 2211.17,928.296 2221.29,908.528 \n",
       "  2231.4,888.621 2241.51,868.594 2251.62,848.467 2261.74,828.26 2271.85,807.994 2281.96,787.686 2292.08,767.359 \n",
       "  \n",
       "  \"/>\n",
       "<path clip-path=\"url(#clip4300)\" d=\"\n",
       "M1989.93 312.204 L2280.76 312.204 L2280.76 130.764 L1989.93 130.764  Z\n",
       "  \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
       "<polyline clip-path=\"url(#clip4300)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1989.93,312.204 2280.76,312.204 2280.76,130.764 1989.93,130.764 1989.93,312.204 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4300)\" style=\"stroke:#009af9; stroke-width:12; stroke-opacity:1; fill:none\" points=\"\n",
       "  2013.93,191.244 2157.93,191.244 \n",
       "  \"/>\n",
       "<g clip-path=\"url(#clip4300)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:start;\" transform=\"rotate(0, 2181.93, 208.744)\" x=\"2181.93\" y=\"208.744\">y1</text>\n",
       "</g>\n",
       "<polyline clip-path=\"url(#clip4300)\" style=\"stroke:#e26f46; stroke-width:12; stroke-opacity:1; fill:none\" stroke-dasharray=\"48, 30\" points=\"\n",
       "  2013.93,251.724 2157.93,251.724 \n",
       "  \"/>\n",
       "<g clip-path=\"url(#clip4300)\">\n",
       "<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:start;\" transform=\"rotate(0, 2181.93, 269.224)\" x=\"2181.93\" y=\"269.224\">y2</text>\n",
       "</g>\n",
       "</svg>\n"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plot(x[:],uf[2][:],ylims = (-0.5,0.5),lw=3)\n",
    "plot!(x[:],(exp(-tspan[2])*sin.(x))[:],ylims = (-0.5,0.5),ls=:dash,lw=3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 1.2.0",
   "language": "julia",
   "name": "julia-1.2"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "1.2.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
